import {HashRouter as Hash, Navigate, useRoutes} from "react-router-dom"
import {Suspense, lazy} from "react"
import Loading from "../components/Loading";

// 主路由
import WebRouter from "./Web/router";


const Err404 = lazy(() => import("./ErrPage/Err404"))
const Err503 = lazy(() => import("./ErrPage/Err503"))
const Login = lazy(() => import("./Login/Login"))
const Register = lazy(() => import("./Login/Register"))
const Forget = lazy(() => import("./Login/ForgetPassword"))

function Path() {
  return useRoutes([
    {path: "/", element: <Navigate replace to="/main/home"/>},
    ...WebRouter,
    // 登录路由
    {path: "/login", element: <Login/>},
    // 注册路由
    {path: "/register", element: <Register/>},
    // 忘记密码路由
    {path: "/forget", element: <Forget/>},
    // 404页面路由
    {path: "/404", element: <Err404/>},
    {path: "/503", element: <Err503/>},
    {path: "*", element: <Err404/>},
  ])
}

function MainRouter() {
  return (
    <Hash>
      <Suspense fallback={<Loading></Loading>}>
        <Path/>
      </Suspense>
    </Hash>
  )
}

export default MainRouter